package cn.org.july.weixin.common.bean.message;

import cn.org.july.weixin.common.constant.WxConstant;
import cn.org.july.weixin.common.interfaces.IMessageData;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;

/**
 * 基础消息父类
 *
 * @auther: wanghongjie
 * @blame: wanghongjie
 * @date: 2020-08-30 16:59
 * @Description:
 */
@Getter
@Setter
public class BaseMessage implements Serializable, IMessageData {

    /**
     * 消息ID 64位整型
     */
    @XStreamAlias("MsgId")
    private String msgId;
    /**
     * 开发者微信号
     */
    @XStreamAlias("ToUserName")
    private String toUserName;
    /**
     * 发送方帐号（一个OpenID）
     */
    @XStreamAlias("FromUserName")
    private String fromUserName;
    /**
     * 消息创建时间 （整型）
     */
    @XStreamAlias("CreateTime")
    private String createTime;
    /**
     * 消息类型，文本为text
     */
    @XStreamAlias("MsgType")
    private String msgType;

    void init(Map<String, Object> map) {
        this.createTime = String.valueOf(map.get(WxConstant.CREATE_TIME));
        this.fromUserName = String.valueOf(map.get(WxConstant.FROM_USER_NAME));
        this.toUserName = String.valueOf(map.get(WxConstant.TO_USER_NAME));
        this.msgType = String.valueOf(map.get(WxConstant.MSG_TYPE));
        this.msgId = String.valueOf(map.get(WxConstant.MSG_ID));
    }

}
